package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;
import com.dongdongshop.pojo.GoodsVO;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.service.ContentCategoryService;
import com.dongdongshop.util.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description
 * @ClassName ContentCategoryController
 * @Author RC
 * @date 2020.12.16 14:53
 */
@Controller
@RequestMapping("contentcategory")
public class ContentCategoryController {
    @Reference(timeout = 100000,check = false)
    private ContentCategoryService contentCategoryService;
    private static final Logger logger = LoggerFactory.getLogger(BrandController.class);

    @RequestMapping("getContentCategoryList")
    @ResponseBody
    public DataResult getContentCategoryList(@RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize,String name) {
        try {
            logger.info("进入广告分类查询方法");
            PageBean<TbContentCategory> contentCategoryList = contentCategoryService.getContentCategoryList(pageNumber, pageSize, name);
            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(contentCategoryList);

        } catch (Exception e) {
            logger.info("查询失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //新建
    @RequestMapping("saveContentCagetory")
    @ResponseBody
    public DataResult saveContentCagetory(TbContentCategory contentCategory){
        //保存  数据有空值 数据库保存异常 ,业务方面导致的没有添加成功 falise
        //可以使用map
        try{
            logger.info("进入增加广告方法");
            contentCategoryService.saveContentCagetory(contentCategory);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        }catch (Exception e){
            logger.info("增加失败",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //回显
    @RequestMapping("getcontentCategoryById/{id}")
    @ResponseBody
    public DataResult toUpdate(@PathVariable("id")Long id){
        try {
            logger.info("进入回显方法");
            TbContentCategory contentCategory = contentCategoryService.getcontentCategoryById(id);
            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(contentCategory);
        }catch (Exception e){
            logger.info("回显失败 ",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //修改
    @RequestMapping("updateContentCagetory")
    @ResponseBody
    public DataResult updateContentCagetory(TbContentCategory contentCategory){
        try {
            logger.info("进入修改方法");
            contentCategoryService.updateContentCagetory(contentCategory);
            return DataResult.response(ResponseStausEnum.SUSSCESS);
        }catch (Exception e){
            logger.info("修改失败 ",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //删除
    @RequestMapping("deleteContentCagetory/{ids}")
    @ResponseBody
    public DataResult deleteContentCagetory(@PathVariable("ids") Long[] ids){
        try {
            logger.info("进入删除方法");
            contentCategoryService.deleteContentCagetory(ids);
            return DataResult.response(ResponseStausEnum.SUSSCESS);
        }catch (Exception e){
            logger.info("删除失败 ",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }


}
